package com.wangjiyuan.giftshuo.ui.activity.classify.shop_details;

import android.content.Intent;
import android.util.Log;

import com.wangjiyuan.giftshuo.bean.classifybean.shop.ShopDetLayoutBean;

import org.greenrobot.eventbus.Subscribe;

import java.util.List;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by QXL on 2016/11/23.
 */

public class ShopDetLayoutPresenter implements ShopDetLayoutContract.IShopDetLayoutPresenter {
    private ShopDetLayoutContract.IShopDetLayoutModel iShopDetLayoutModel;
    private ShopDetLayoutContract.IShopDetLayoutView iShopDetLayoutView;

    private Subscription subscribe;
    public ShopDetLayoutPresenter(ShopDetLayoutContract.IShopDetLayoutView view){
        this.iShopDetLayoutView=view;
        iShopDetLayoutModel=new ShopDetLayoutModel();
    }
    @Override
    public void getShopDetLayoutObservable(int id, Map<String, Integer> paramsMap) {
        Observable<ShopDetLayoutBean> shopDetLayoutObservable = iShopDetLayoutModel.getShopDetLayoutObservable(id, paramsMap);
        subscribe = shopDetLayoutObservable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ShopDetLayoutBean>() {
                    @Override
                    public void onStart() {
                        Log.e("ShopDetLayout","start");
                        super.onStart();
                    }

                    @Override
                    public void onCompleted() {
                        Log.e("ShopDetLayout","completed");
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("ShopDetLayout","error");
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onNext(ShopDetLayoutBean shopDetLayoutBean) {
                        Log.e("ShopDetLayout","next");
                        iShopDetLayoutView.loadShopDetLayoutData(shopDetLayoutBean);
                    }
                });
    }
}
